<!doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  <title>社区</title>
  <link rel="stylesheet" type="text/css" href="../css/api.css" />
  <link rel="stylesheet" type="text/css" href="../css/dynamic.css" />
</head>

<body>
  <div id="app" v-cloak>
    <div class="wrap flex-wrap flex-vertical">
      <header id="header">
        <div class="header-wrap">
          <div @click="goback" class="header-left">
            <i class="iconfont icon-pre"></i>
          </div>
          <div class="nav">
            <a href="javascript:;" :class="indexDynamic==0?'active':''" tapmode @click="setDynamic(0)" class="nav-left">关注</a>
            <a href="javascript:;" :class="indexDynamic==1?'active':''" tapmode @click="setDynamic(1)" class="nav-left">推荐</a>
            <a href="javascript:;" :class="indexDynamic==2?'active':''" tapmode @click="setDynamic(2)" class="nav-right">附近</a>
          </div>
          <div @click="publish" class="header-right">
            <i class="iconfont icon-font-add1"></i>
          </div>
        </div>
      </header>
      <div id="main" class="home-main flex-con"></div>
    </div>
  </div>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
  var app;
  apiready = function () {
    $api.fixStatusBar($api.dom('#header'));
    app = new Vue({
      el: '#app',
      data: {
        indexDynamic: 1,
        userInfo: {},
        certification: '0',
      },
      created: function () {
        var _this = this;
      },
      mounted: function () {
        var _this = this;
        _this.openDynamicGroup();
        _this.getUserIndex();
      },
      methods: {
        goback: function () {
          api.closeWin();
        },

        //首页Tab切换
        openDynamicGroup: function () {
          var _this = this;
          api.openFrameGroup({
            name: 'dynamicGroup',
            rect: {
              x: 0,
              y: $api.dom('#header').offsetHeight,
              w: api.winWidth,
              h: $api.dom('#main').offsetHeight,
            },
            frames: [{
              name: 'dynamic_follow',
              url: 'dynamic_follow.html',
              bgColor: '#fff'
            }, {
              name: 'dynamic',
              url: 'dynamic.html',
              bgColor: '#fff'
            }, {
              name: 'dynamic_local',
              url: 'dynamic_local.html',
              bgColor: '#fff'
            }],
            index: _this.indexDynamic
          }, function (ret, err) {
            _this.indexDynamic = ret.index;
          })
        },

        //首页点击切换Tab
        setDynamic: function (index) {
          api.setFrameGroupIndex({
            name: 'dynamicGroup',
            index: index
          })
        },

        getUserIndex: function () {
          var _this = this;
          api.ajax({
            url: baseUrl + 'user/index',
            method: 'get',
            headers: {
              token: $api.getStorage('deviceToken')
            },
            data: {
              values: {
                uid: $api.getStorage('uid'),
              },
            }
          }, function (ret, err) {
            if (ret.status == 200) {
              _this.userInfo = ret.data;
              _this.certification = ret.data.certification;
            }
          })
        },

        //发表动态
        publish: function () {
          var _this = this;
          // if (_this.userInfo.certification == '0') {
					// 	api.alert({
					// 		title: '提示', 
					// 		msg: '您还未认证，请认证之后发布动态'
					// 	}, function (ret) {
					// 		if (ret.buttonIndex == 1) {
					// 			api.openWin({
					// 				name: 'my_auth',
					// 				url: 'my_auth.html',
					// 				bounces: false,
					// 				pageParam: _this.userInfo
					// 			});
					// 		}
					// 	});
					// 	return false;
          // }
					// if (_this.userInfo.certification == '2') {
					// 	api.alert({
					// 		title: '提示', 
					// 		msg: '认证中，请耐心等待'
					// 	});
					// 	return false;
          // }
          api.openWin({
            name: 'dynamic_post',
            url: 'dynamic_post.html',
            slidBackEnabled: false
          })
        },

      },

      filters: {
        // getStatus: function (value) {
        //   if (value == '0') {
        //     return '离线';
        //   }
        //   if (value == '1') {
        //     return '在线';
        //   }
        //   if (value == '2') {
        //     return '离开';
        //   }
        //   if (value == '4') {
        //     return '忙碌';
        //   }
        // },
      }
    })

  }
</script>